Coverage Report

Created: 2021-08-28 18:14

D:\git\skunkworks\herald-for-cpp\herald-tests\gaussian-tests.cpp
Line
Count
Source
1
//  Copyright 2021 Herald project contributors
2
//  SPDX-License-Identifier: Apache-2.0
3
//
4
5
#include "catch.hpp"
6
7
#include "herald/herald.h"
8
9
#include <utility>
10
#include <iostream>
11
12
using namespace herald::analysis::sampling;
13
using namespace herald::datatype;
14
15
// template <std::size_t Sz>
16
// struct DummyRSSISource {
17
//   using value_type = Sample<RSSI>; // allows AnalysisRunner to introspect this class at compile time
18
19
//   DummyRSSISource(const std::size_t srcDeviceKey, SampleList<Sample<RSSI>,Sz>&& data) : key(srcDeviceKey), data(std::move(data)) {};
20
//   ~DummyRSSISource() = default;
21
22
//   template <typename RunnerT>
23
//   void run(int timeTo, RunnerT& runner) {
24
//     // push through data at default rate
25
//     for (auto& v: data) {
26
//       // devList.push(v.taken,v.value); // copy data over (It's unusual taking a SampleList and sending to a SampleList)
27
//       if (v.taken.secondsSinceUnixEpoch() <= timeTo) {
28
//         runner.template newSample<RSSI>(key,v);
29
//       }
30
//     }
31
//     runner.run(Date(timeTo));
32
//   }
33
34
// private:
35
//   std::size_t key;
36
//   SampleList<Sample<RSSI>,Sz> data;
37
// };
38
39
// struct DummyDistanceDelegate /* : herald::analysis::AnalysisDelegate */ {
40
//   using value_type = Distance;
41
42
//   DummyDistanceDelegate() : lastSampledID(0), distances() {};
43
//   DummyDistanceDelegate(const DummyDistanceDelegate&) = delete; // copy ctor deleted
44
//   DummyDistanceDelegate(DummyDistanceDelegate&& other) noexcept : lastSampledID(other.lastSampledID), distances(std::move(other.distances)) {} // move ctor
45
//   ~DummyDistanceDelegate() {};
46
47
//   DummyDistanceDelegate& operator=(DummyDistanceDelegate&& other) noexcept {
48
//     lastSampledID = other.lastSampledID;
49
//     std::swap(distances,other.distances);
50
//     return *this;
51
//   }
52
53
//   // specific override of template
54
//   void newSample(SampledID sampled, Sample<Distance> sample) {
55
//     lastSampledID = sampled;
56
//     distances.push(sample);
57
//   }
58
59
//   void reset() {
60
//     distances.clear();
61
//     lastSampledID = 0;
62
//   }
63
64
//   // Test only methods
65
//   SampledID lastSampled() {
66
//     return lastSampledID;
67
//   }
68
69
//   const SampleList<Sample<Distance>,25>& samples() {
70
//     return distances;
71
//   }
72
73
// private:
74
//   SampledID lastSampledID;
75
//   SampleList<Sample<Distance>,25> distances;
76
// };
77
78
79
1
TEST_CASE("aggregates-gaussian-empty", "[aggregates][gaussian][empty][basic]") {
80
1
  SECTION("aggregates-gaussian-empty") {
81
1
    herald::analysis::aggregates::Gaussian g;
82
1
83
1
    REQUIRE(g.reduce() == 0.0);
84
1
    REQUIRE(g.model().count() == 0);
85
1
    REQUIRE(g.model().min() != 0);
86
1
    REQUIRE(g.model().max() != 0);
87
1
  }
88
1
}
89
90
1
TEST_CASE("aggregates-gaussian-mapreduce", "[aggregates][gaussian][mapreduce][basic]") {
91
1
  SECTION("aggregates-gaussian-mapreduce") {
92
1
    herald::analysis::aggregates::Gaussian g;
93
1
    double sum = 0.0;
94
1
    std::size_t count = 0;
95
11
    for (std::int8_t i = 0;i < 10; 
++i10
) {
96
10
      g.map(herald::analysis::Sample(herald::datatype::Date(0),i));
97
10
      sum += i;
98
10
      ++count;
99
10
      REQUIRE(((g.reduce() == sum / count) || (g.reduce() == 0.0)));
100
10
    }
101
1
    REQUIRE(g.model().count() == 10);
102
1
    REQUIRE(g.model().min() == 0);
103
1
    REQUIRE(g.model().max() == 9);
104
1
    // g.reduce value test too (in expected range for data given)
105
1
    REQUIRE(g.reduce() == sum / count);
106
1
  }
107
1
}
108
109
1
TEST_CASE("aggregates-gaussian-reset", "[aggregates][gaussian][reset][basic]") {
110
1
  SECTION("aggregates-gaussian-reset") {
111
1
    herald::analysis::aggregates::Gaussian g;
112
1
    g.map(herald::analysis::Sample(herald::datatype::Date(0),5));
113
1
114
1
    g.reset();
115
1
116
1
    REQUIRE(g.reduce() == 0.0);
117
1
    REQUIRE(g.model().count() == 0);
118
1
    REQUIRE(g.model().min() != 0);
119
1
    REQUIRE(g.model().max() != 0);
120
1
  }
121
1
}